<template>
	<view>
		<view>
			<!-- <input type="text" v-model="businessName" placeholder="请输入">
			
			<view class="yes" @tap="handleClickYes">确定</view> -->
			<input type="text" placeholder="请输入行业类型名称" v-model="businessName" class="ipt-source">
			
			<!-- <view class="yes" >确定</view> -->
			<view class="btn-confirm" @tap="handleClickYes">确定</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				token:'',
				businessName:'',
				msg:'',
				changeId:'',
			}
		},
		onLoad(option){
			// console.log(option.id)
			// this.changeId = option.id;
			if(option.item){
				let list = JSON.parse(option.item)
				this.businessName = list.b_t_name;
				this.changeId = list.id;
			}
		},
		methods:{
			// 取token
			getToken(){
				try {
				    const value = uni.getStorageSync('login_key');
				    if (value) {
						this.token = value;
				    }
				} catch (e) {
				    // error
				}
			},
			// 点确定发请求
			async handleClickYes(){
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				var prevPage = pages[pages.length - 2]; //上一个页面
				//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
				prevPage && prevPage.setData && prevPage.setData({
				        isDoRefresh:true
				});
				this.getToken()
				// 发请求
				let url = this.ServicesApi.businessTypeCreateEdit;
				let data = {
				    business_type_name:this.businessName,
				    id: this.changeId || '', //有值就是修改，没值就是新增
				};
				if (!this.businessName) {
					return uni.showToast({
						icon: 'none',
						title: '请输入行业类型名称'
					});
				}
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
				    uni.showToast({
				        icon: 'none',
				        title: result.msg,
				    });
				    setTimeout(() => {
				    	uni.navigateBack({
				    		delta: 1,
				    		animationType: 'pop-out',
				    		animationDuration: 200
				    	});
				    }, 1500);
				} else {
				    uni.showToast({
				        icon: 'none',
				        title: result.msg,
				    });
				}
				// uni.request({
				//     url: this.ServicesApi.businessTypeCreateEdit, 
				// 	method:'POST',
				// 	header: {
						
				// 		"content-type":"application/x-www-form-urlencoded"
				// 	},
				//     data: {
				// 		token:this.token,
				// 		business_type_name:this.businessName,
				// 		id:this.changeId || '',  //id有值就是更改，不然就是添加
				//     },
				//     success: (res) => {
				// 		if(res.data.code == 0){
				// 			uni.showToast({
				// 							icon: 'none',
				// 							title: res.data.msg,
				// 						});
				// 			return false
				// 		}else{
				// 			uni.navigateBack({
				// 				delta: 1,
				// 				animationType: 'pop-out',
				// 				animationDuration: 200
				// 			});
				// 			uni.showToast({
				// 				title: res.data.msg
				// 			});
				// 		}
				// 		// console.log(res.data)
				//     }
				// });
			}
		},
		mounted(){
			
		}
	}
</script>

<style scoped lang="stylus">
	.msg{
		height:30upx;
		font-size:28upx;
		color:red;
	}
	.ipt-source{
		height:110upx;
		background:#fff;
		padding:0 40upx;
		font-size:32upx;
	}
	.btn-confirm{
		height:76upx;
		width:440upx;
		background:linear-gradient(270deg,rgba(0,106,231,1) 0%,rgba(66,157,255,1) 100%);
		color:#fff;
		font-size:32upx;
		text-align:center;
		line-height:76upx;
		margin:80upx auto;
	}
</style>
